/**
 * 
 */
package com.csc.bankingsystem.core.dao.impl;

import java.util.List;

import org.apache.commons.collections.CollectionUtils;
import org.hibernate.Criteria;
import org.hibernate.criterion.Restrictions;
import org.springframework.stereotype.Repository;

import com.csc.bankingsystem.core.dao.AccountInfoDAO;
import com.csc.bankingsystem.core.entity.AccountInfo;

/**
 * Define all Data access operations of AccountInfoDAO
 * 
 * @author angelkid
 *
 */
@Repository("accountInfoDAO")
public class AccountInfoDAOImpl extends GenericDAOImpl<AccountInfo> implements
		AccountInfoDAO {

	public List<AccountInfo> findAllByUserInfoId(long id) {
		Criteria criteria = getSession().createCriteria(AccountInfo.class);
		criteria.add(Restrictions.eq("userInfo.id", id));
		@SuppressWarnings("unchecked")
		List<AccountInfo> list = criteria.list();
		return (CollectionUtils.isEmpty(list))?null:list;
	}

	public AccountInfo findByAccountNumber(String number) {
		Criteria criteria = getSession().createCriteria(AccountInfo.class);
		criteria.add(Restrictions.eq("number", number));
		return (AccountInfo) criteria.uniqueResult();
	}
	
}
